package com.arrogames.blondbattle.ui 
{
	import com.greensock.TweenMax;
	import starling.display.Sprite;
	import starling.text.TextField;
	
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class LoadingDisplay extends Sprite {
		private var funnyLineDisplay:TextField;
		private var loadingDisplay:TextField;
		
		//Displayed while loading the assets.
		private var funnylines:Array = [
			"TWERKING ARNIE", 
			"GET READY FOR OFF BLAST",
			"POWERED BY HYPNO TOAD",
			"WHAAAAAAAAAAAAAAAAAAAAAAAAAAT"];
		
		public function LoadingDisplay() {
			super();
			
			funnyLineDisplay = new TextField(800, 340, funnylines[0]);
			funnyLineDisplay.fontName = "comic";
			funnyLineDisplay.color = 0xffffff;
				
			loadingDisplay = new TextField(800, 240, "LOADING ...");
			loadingDisplay.fontName = "comic";
			loadingDisplay.fontSize = 28;
			loadingDisplay.color = 0xffffff;
			
			addChild(funnyLineDisplay);
			addChild(loadingDisplay);
		}
		
		public function assetProgress(ratio:Number):void {
			if (ratio == 0) {
				TweenMax.to(loadingDisplay, 1.5, {alpha:0.1, repeat:-1, repeatDelay:0.1, yoyo:true});
			}
			
			var index:int = Math.max(Math.round(funnylines.length * ratio)-1, 0);
			funnyLineDisplay.text = funnylines[index] as String;
		}
		
		override public function dispose():void {
			super.dispose();
			TweenMax.killTweensOf(loadingDisplay);
		}
		
	}

}